package com.tecklab.demo.utils;

import ch.qos.logback.classic.Level;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LogConsolehUtils {

    /**
     * 关闭日志打印
     */
    public static void disable(){
        // 关闭日志框架日志打印
        Logger logger = LoggerFactory.getILoggerFactory().getLogger(Logger.ROOT_LOGGER_NAME);
        if (logger instanceof ch.qos.logback.classic.Logger) {
            ch.qos.logback.classic.Logger logbackLogger = (ch.qos.logback.classic.Logger) logger;
            logbackLogger.setLevel(ch.qos.logback.classic.Level.OFF);
        }
//        else if (logger instanceof org.apache.log4j.Logger) {
//            org.apache.log4j.Logger log4jLogger = (org.apache.log4j.Logger) logger;
//            log4jLogger.setLevel(org.apache.log4j.Level.OFF);
//        }
    }

    public static void setInfoLevel(){
        // 关闭日志框架日志打印
        Logger logger = LoggerFactory.getILoggerFactory().getLogger(Logger.ROOT_LOGGER_NAME);
        if (logger instanceof ch.qos.logback.classic.Logger) {
            ch.qos.logback.classic.Logger logbackLogger = (ch.qos.logback.classic.Logger) logger;
            logbackLogger.setLevel(Level.INFO);
        }
//        else if (logger instanceof org.apache.log4j.Logger) {
//            org.apache.log4j.Logger log4jLogger = (org.apache.log4j.Logger) logger;
//            log4jLogger.setLevel(org.apache.log4j.Level.INFO);
//        }
    }

    public static void setDebugLevel(){
        // 关闭日志框架日志打印
        Logger logger = LoggerFactory.getILoggerFactory().getLogger(Logger.ROOT_LOGGER_NAME);
        if (logger instanceof ch.qos.logback.classic.Logger) {
            ch.qos.logback.classic.Logger logbackLogger = (ch.qos.logback.classic.Logger) logger;
            logbackLogger.setLevel(Level.DEBUG);
        }
//        else if (logger instanceof org.apache.log4j.Logger) {
//            org.apache.log4j.Logger log4jLogger = (org.apache.log4j.Logger) logger;
//            log4jLogger.setLevel(org.apache.log4j.Level.DEBUG);
//        }
    }
}
